import { Directive } from 'vue';
import { useUserStore } from '../store/user';

export const permission: Directive = {
    mounted(el, binding) {
        const { value } = binding;
        const userStore = useUserStore();
        if (userStore.userInfo.groupId === 1) return true
        let menu = userStore.menuBottons.find((item: { roleCode: string; }) => item.roleCode === value) ?? null
        if (menu != null && userStore.userInfo.systemRole.includes(menu.id)) {
            return true;
        } else {
            el.parentNode && el.parentNode.removeChild(el);
            return false;
        }
    }
}

